# -*- coding: utf-8 -*-
# @File: sendmail.py
# @Author: Liccsu
# @Time: 12/8/2022 下午10:20
# @Project: eschool-health

from datetime import datetime

try:
    from cfg import Cfg
    from mail import EMail
except ModuleNotFoundError or ImportError:
    from .cfg import Cfg
    from .mail import EMail


class SendMail(EMail):
    def __init__(self):
        super(SendMail, self).__init__()
        self.address = Cfg.recv_mail
        self.title = '健康打卡通知'

    def create_schedule_success(self):
        now_time = datetime.now().strftime("%Y年-%m月-%d日 %H:%M:%S")
        content = "自动任务创建成功\n————" + now_time
        self.send_email(
            address=self.address,
            title="任务创建通知",
            content=content
        )

    def send_error(self, err):
        now_time = datetime.now().strftime("%Y年-%m月-%d日 %H:%M:%S")
        self.send_email(
            address=self.address,
            title="程序异常通知",
            content=str(err) + "\n————" + now_time
        )

    def send_success(self, data: dict):
        now_time = datetime.now().strftime("%Y年-%m月-%d日 %H:%M:%S")
        content = "今日易校园健康打卡成功\n" + "地点：" + data['data']['locationInfo'] + "\n————" + now_time
        self.send_email(
            address=self.address,
            title=self.title,
            content=content
        )
        # print('成功')

    def send_failed(self, data: dict = None):
        if data is None:
            data = {'statusCode': -999, 'message': '打卡失败'}
        now_time = datetime.now().strftime("%Y年-%m月-%d日 %H:%M:%S")
        content = "今日易校园健康打卡失败\nstatusCode: " + data["statusCode"] + "\nmessage: " + data[
            'message'] + "\n————" + now_time
        self.send_email(
            address=self.address,
            title=self.title,
            content=content
        )
        # print('失败')


sm = SendMail()

if __name__ == '__main__':
    print(sm)
